// pages/firstpage/firstpage.js
const db = wx.cloud.database()
const _ = db.command
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    total_hours:'80',
    my_total_numbers:'0',
    program_total_numbers:'',
    functions:[
      {
        name:'我的项目',
        numbers:'1',
        iconpath:'/images/logo.jpg',
        classifier:"个",
        path:"../myprogram/myprogram"
      },
      {
        name: '项目广场',
        numbers: '2',
        iconpath: '/images/logo.jpg',
        classifier: "个",
        path:"../programsqure/programsqure",
      },
      {
        name: '我的邮箱',
        numbers: '3',
        iconpath: '/images/logo.jpg',
        classifier: "封",
        path:"../mymailbox/mymailbox"
      },
      {
        name: '优秀志愿者',
        numbers: '',
        iconpath: '/images/logo.jpg',
        classifier: "",
        path:"../bestvolunteer/bestvolunteer"
      }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },
  login: function() {
    wx.navigateTo({
      url: '../login/login',
    })
  },
  tofunction1: function () {
    wx.navigateTo({
      url: '../myEvents/firstPage/firstPage'
    })
  },
  tofunction2: function () {
    wx.navigateTo({
      url: '../programSqure/programSqure'
    })
  },
  tofunction3: function () {
    wx.navigateTo({
      url: '../mymailbox/mymailbox'
    })
  },
  tofunction4: function () {
    wx.navigateTo({
      url: '../bestvolunteer/bestvolunteer'
    })
  },

  onLoad: function(options) {
    if (app.globalData.openid) {
      this.setData({
        openid: app.globalData.openid
      })
    }
  },

  onQuery: function() {
    db.collection('Events').where({
      _openid: this.data.openid
    }).get({
      success: res => {
        this.setData({
          queryResult: JSON.stringify(res.data, null, 2)
        })
        console.log('[数据库] [查询记录] 成功: ', res)
      },
      fail: err => {
        wx.showToast({
          icon: 'none',
          title: '查询记录失败'
        })
        console.error('[数据库] [查询记录] 失败：', err)
      }
    })
  },



})